package com.download;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Upload extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("**********-------------");
		InputStream in = req.getInputStream();
		File f = new File("d:", "Baaa.txt");
		FileOutputStream o = new FileOutputStream(f);
		byte b[] = new byte[1000];
		int n;
		while ((n = in.read(b)) != -1)
		{
			o.write(b, 0, n);
		}
		o.close();
		in.close();

		
		
		// InputStream is = req.getInputStream();
		// byte[] b = new byte[1024];
		// int count = is.read(b);
		//
		// FileOutputStream fos = new FileOutputStream("D://aa.txt");
		// while(count != -1) {
		// fos.write(b, 0, count);
		// System.out.println("--****--");
		// count = is.read(b);
		// }
		// System.out.println("--123");

		// InputStream is = req.getInputStream();
		// Reader reader = new InputStreamReader(is);
		// BufferedReader br = new BufferedReader(reader);
		// System.out.println("----*******上传成功");
		//
		// int str = br.read();
		// while(str != -1) {
		// System.out.println((char)str);
		// str = br.read();
		// System.out.println("----");
		//
		// }

	}

}
